package com.tueye.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.tueye.base.util.IBaseHbnDao;
import com.tueye.dao.ITopicTypeDao;
import com.tueye.entity.TopicType;
import com.tueye.utils.UUIDGenerator;

@Scope("prototype")
@Component("topicTypeDao")
public class TopicTypeDaoImpl implements ITopicTypeDao {

	@Autowired
	@Qualifier("baseHbnDao")
	private IBaseHbnDao  baseHbnDao;
	
	@Override
	public List<TopicType> getParentData() {
		TopicType tp = new TopicType();

		String hql = "from com.tueye.entity.TopicType topicType where topicType.pid is null" ;
		return baseHbnDao.queryList(hql);
	}

	@Override
	public List<TopicType> getDataByParentId(String id) {
		String hql = "from com.tueye.entity.TopicType topicType where topicType.pid='" + id + "'";
		return baseHbnDao.queryList(hql);
	}

	@Override
	public String addTopicType(String[] value) {
		TopicType tp = new TopicType();
		//设置
		tp.setPid(value[0]);
		//tp.setId(value[1]);
		tp.setId(new UUIDGenerator().getUUID());
		tp.setType_name(value[1]);
		tp.setType_enlish_name(value[2]);
		tp.setType_page_description(value[3]);
		tp.setType_page_keywords(value[4]);
		tp.setType_page_title(value[5]);
		String next = "success";
		try{
			baseHbnDao.save(tp);
		}catch(Exception e){
			next = "fail";
			e.printStackTrace();
		}
		return next;
	}

	@Override
	public String deleteTopicType(String[] value) {
		TopicType topicType =(TopicType) baseHbnDao.findById(TopicType.class, value[0]);
		baseHbnDao.delete(topicType);
		return null;
	}

	@Override
	public String updateTopicType(String[] value) {
		TopicType topicType = (TopicType)baseHbnDao.findById(TopicType.class, value[0]);
		System.out.println("topicType__"+topicType+"_---" + value[1]);
		topicType.setType_name(value[1]);
		topicType.setType_enlish_name(value[2]);
		topicType.setType_page_description(value[3]);
		topicType.setType_page_keywords(value[4]);
		topicType.setType_page_title(value[5]);
		baseHbnDao.saveOrUpdate(topicType);
		return null ;
	}

	@Override
	public TopicType getNodeInfoById(String id) {
		return (TopicType)baseHbnDao.findById(TopicType.class, id);
	}

}
